package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.Brand;
import com.sailfish.springbootdemo.pojo.db1.LineBaseBigType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface LineBaseBigTypeDao {

    /**
     * 查询所有的
     *
     * @param searchValue
     * @return
     */
    @Results(id = "lineBaseBigTypeResultMap", value = {
            @Result(column = "line_base_big_type_id", property = "lineBaseBigTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "line_base_big_type_name", property = "lineBaseBigTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "pcba_device_type_id", property = "pcbaDeviceTypeId", jdbcType = JdbcType.INTEGER),
    })
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_BASE_BIG_TYPE + " where 1 = 1 " +
            "<if test='searchValue != null and searchValue != \"\" '>" +
            " and line_base_big_type_name like CONCAT('%',#{searchValue},'%')" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<LineBaseBigType> getAllLineBaseBigType(@Param("searchValue") String searchValue);

    @ResultMap(value = "lineBaseBigTypeResultMap")
    @Select("select * from " + DB1TableName.LINE_BASE_BIG_TYPE + " where line_base_big_type_name = #{lineBaseBigTypeName}")
    List<LineBaseBigType> getLineBaseBigTypeByName(@Param("lineBaseBigTypeName") String lineBaseBigTypeName);

    /**
     * 根据id查询
     *
     * @param lineBaseBigTypeId
     * @return
     */
    @Select("select * from " + DB1TableName.LINE_BASE_BIG_TYPE + " where line_base_big_type_id = #{lineBaseBigTypeId}")
    @ResultMap(value = "lineBaseBigTypeResultMap")
    LineBaseBigType getLineBaseBigTypeById(@Param("lineBaseBigTypeId") Integer lineBaseBigTypeId);

    /**
     * 判断有没有重复的
     *
     * @return
     */
    @ResultMap(value = "lineBaseBigTypeResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_BASE_BIG_TYPE + " where line_base_big_type_name = #{lineBaseBigTypeName} " +
            "<if test='lineBaseBigTypeId != null and lineBaseBigTypeId != \"\" '>" +
            " and line_base_big_type_id != #{lineBaseBigTypeId}" +
            "</if>" +
            "</script>")
    List<LineBaseBigType> judgeUniqueLineBaseBigType(@Param("lineBaseBigTypeId") Integer lineBaseBigTypeId, @Param("lineBaseBigTypeName") String lineBaseBigTypeName);

    /**
     * 新增
     *
     * @param lineBaseBigType
     * @return
     */
    @Insert("insert into " + DB1TableName.LINE_BASE_BIG_TYPE + "(line_base_big_type_name,status,sort,create_time,pcba_device_type_id) values " +
            "(#{lineBaseBigType.lineBaseBigTypeName},#{lineBaseBigType.status},#{lineBaseBigType.sort},#{lineBaseBigType.createTime},#{lineBaseBigType.pcbaDeviceTypeId})")
    Integer addLineBaseBigType(@Param("lineBaseBigType") LineBaseBigType lineBaseBigType);

    /**
     * 更新
     *
     * @param lineBaseBigType
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.LINE_BASE_BIG_TYPE +
            "<set>" +
            "<if test='lineBaseBigType.lineBaseBigTypeName != null and lineBaseBigType.lineBaseBigTypeName != \"\" '>" +
            " line_base_big_type_name = #{lineBaseBigType.lineBaseBigTypeName}," +
            "</if>" +
            "<if test='lineBaseBigType.pcbaDeviceTypeId != null and lineBaseBigType.pcbaDeviceTypeId != \"\" '>" +
            " pcba_device_type_id = #{lineBaseBigType.pcbaDeviceTypeId}," +
            "</if>" +
            "<if test='lineBaseBigType.sort != null and lineBaseBigType.sort != \"\" '>" +
            " sort = #{lineBaseBigType.sort}," +
            "</if>" +
            "<if test='lineBaseBigType.updateTime != null '>" +
            " update_time = #{lineBaseBigType.updateTime}," +
            "</if>" +
            "</set>" +
            " where line_base_big_type_id = #{lineBaseBigType.lineBaseBigTypeId}" +
            "</script>")
    Integer updateLineBaseBigType(@Param("lineBaseBigType") LineBaseBigType lineBaseBigType);

    /**
     * 删除
     *
     * @param lineBaseBigTypeId
     * @return
     */
    @Delete("delete from " + DB1TableName.LINE_BASE_BIG_TYPE + " where line_base_big_type_id = #{lineBaseBigTypeId}")
    Integer deleteLineBaseBigType(@Param("lineBaseBigTypeId") Integer lineBaseBigTypeId);
}
